package com.yuehuanghun.admin.quartz.domain;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Transient;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonFormat.Shape;
import com.yuehuanghun.admin.core.config.MyExampleQueryConverter;
import com.yuehuanghun.framework.annotation.Excel;
import com.yuehuanghun.mybatis.milu.annotation.AttributeOptions;
import com.yuehuanghun.mybatis.milu.annotation.ExampleQuery;
import com.yuehuanghun.mybatis.milu.annotation.Filler;
import com.yuehuanghun.mybatis.milu.annotation.ExampleQuery.MatchType;
import com.yuehuanghun.mybatis.milu.tool.Constants;

import lombok.Data;

/**
 * 定时任务调度日志表 sys_job_log
 * 
 * @author yadmin
 */
@Entity
@Data
public class SysJobLog implements Serializable {
	private static final long serialVersionUID = 1L;

	/** ID */
	@Excel(name = "日志序号")
	@Id
	@GeneratedValue(generator = Constants.ID_GENERATOR_SNOWFLAKE)
	@JsonFormat(shape = Shape.STRING)
	private Long jobLogId;

	/** 任务名称 */
	@Excel(name = "任务名称")
	@AttributeOptions(exampleQuery = @ExampleQuery(matchType = MatchType.CONTAIN))
	private String jobName;

	/** 任务组名 */
	@Excel(name = "任务组名")
	private String jobGroup;

	/** 调用目标字符串 */
	@Excel(name = "调用目标字符串")
	@AttributeOptions(exampleQuery = @ExampleQuery(matchType = MatchType.CONTAIN))
	private String invokeTarget;

	/** 日志信息 */
	@Excel(name = "日志信息")
	private String jobMessage;

	/** 执行状态（0正常 1失败） */
	@Excel(name = "执行状态", readConverterExp = "0=正常,1=失败")
	private String status;

	/** 异常信息 */
	@Excel(name = "异常信息")
	private String exceptionInfo;

	/** 开始时间 */
	private Date startTime;

	/** 停止时间 */
	private Date stopTime;

	/** 创建时间 */
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@AttributeOptions(filler = @Filler(fillOnInsert = true), exampleQuery = @ExampleQuery(startKeyName = "params.beginTime", endKeyName = "params.endTime", valueConverter = MyExampleQueryConverter.class))
	private Date createTime;	

	/** 请求参数 */
	@Transient
    private Map<String, Object> params;

	public Map<String, Object> getParams() {
		return params == null ? (params = new HashMap<>()) : params;
	}
}
